๐ [hanse & sally] ๋ก๋ 2๋จ๊ณ - ๋ณด๋์ค ๋ฒํธ ์ถ๊ฐ#45
๐ [hanse & sally] ๋ก๋ 2๋จ๊ณ - ๋ณด๋์ค ๋ฒํธ ์ถ๊ฐ#45rkolx wants to merge 15 commits intocodesquad-members-2022:sally-kshfrom
Conversation
- ๋ณด๋์ค๋ณผ ์ ๋ ฅ ์ถ๊ฐ
- WinningNumber ํด๋์ค ์์ฑ - Winnings ํด๋์ค์์ WinningNumberCouter๋ก ํด๋์ค ๋ช ์์
- Lottos ํด๋์ค : ๋ณด๋์ค ๋ฒํธ ์ถ๊ฐํ์ฌ ๊ฐ์ ์ธ๊ธฐ
- Main.class -> LottoPlay - Lottos getNumberOfWinningAboveThree() -> Ranking ์๊ฒ ์ ๋ฌ - Ranking - this.ranking ๋ฐํ์ ์์ ํ๊ฒ ์ํด String์ผ๋ก์ ๋ณ๊ฒฝ๋ก์ง์ ์ฎ๊น
- BasicWinningNumbers - ๊ธฐ์กด์ ๋ก๋ ๊ฒฐ๊ณผ ์ถ๋ ฅ ๊ธฐ๋ฅ - AddedWinningNumbers - ๊ธฐ์กด์ ๋ก๋ ๊ฒฐ๊ณผ์ ์ถ๊ฐ๋๋ ๋ณด๋์ค ์ซ์๋ค ์ ๋ฌ - BonusWinningNumbers ๊ตฌํ์ฒด
- UserLotto - ์ ๋ ฅ๋ฐ์ ์ฌ์ฉ์ ์์ฒญ์ ํตํด ๋ก๋ ์์ฑ, ๋ณด๊ด, ๋น์ฒจ ๊ฒฐ๊ณผ์์ ๋งค์นญ ๊ธฐ๋ฅ์ ๊ฐ์ง๋ค.
- ๋น์ฆ๋์ค ๋ก์ง์ ๋๋๋ฉด์ ์ฌ์ฉ์๊ฐ ๊ฐ์ง ํฐ์ผ ์ ๋ณด์ ๋น์ฒจ ์ ๋ณด๋ฅผ ํจํค์ง๋ก ๋ถ๋ฆฌ
- Lottos ํด๋์ค : getTotalLottos()์์ ๊ตฌ๋งคํ ๊ฐ์๋งํผ ๋ก๋ ๋ฒํธ ๋ด๋ getPurchassedLotoos() ์ถ๊ฐ ๋ถ๋ฆฌ
- Lottos ํด๋์ค : getTotalLottos() ๋ด ๋ก๋ ๋ฒํธ ๋ด๋ ๋ถ๋ถ toLottos() ์์ฑํ์ฌ ๋ถ๋ฆฌ
- LottoPlayํด๋์ค๋ช ์์ LottoApplicationํด๋์ค๋ช ์ผ๋ก ๋ณ๊ฒฝ
wheejuni
left a comment
There was a problem hiding this comment.
์๊ณ ๋ง์ผ์
จ์ต๋๋ค ๐ฏ
์ฝ๋ฉํธ ์ฐธ๊ณ ํด์ฃผ์ธ์~
| private static LottoMachine lottoMachine = new LottoMachine(); | ||
| private static Lottos lottos = new Lottos(); | ||
| private static UserLotto userLotto = new UserLotto(lottoMachine, lottos); |
There was a problem hiding this comment.
์ด ๋ถ๋ถ์ ์ด๋ป๊ฒ ๊ฐ์ ํ๋ฉด ์ข์์ง 3๋จ๊ณ์์ ๊ณ ๋ฏผํด์ฃผ์ธ์~
ํํธ: LottoGame ๋ถ๋ฆฌ, ์์กด์ฑ ์ฃผ์
There was a problem hiding this comment.
์ผ-์.... ์ด๋ ต์ง๋ง, ์ ๊ฒ๋ ๊ฐ๊ณ ... @_@๊ณ ๋ฏผ ํด์ ๊ฐ์ ๋๋๋ก ๋
ธ๋ ฅํ๊ฒ ์ต๋๋ค.
3๋จ๊ณ ์งํํ๋ฉด์ ์คํ ,์๋๋ง di๋ก ํ๋๋ฐ๋, ๋ณด์ง ๋ชปํ ๋ถ๋ถ์ด ์๋ ๊ฑฐ ๊ฐ์์.
์๋ ค์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค.๐ฅ
| public static void main(String[] args) { | ||
| PurchasedLotto purchasedLotto = purchaseLotto(); | ||
|
|
||
| List<List<Integer>> totalLottos = userLotto.getTickets(purchasedLotto); |
There was a problem hiding this comment.
List<List<T>> ์ 2์ฐจ์ ๋ฐฐ์ด๊ณผ์ ์ฐจ์ด์ ์ด ๋ฌด์์ผ๊น์?
There was a problem hiding this comment.
2์ฐจ์ ๋ฐฐ์ด์ ์ฐจ์ด์ ๊ณผ ๋ฆฌ์คํธ์ ์ฅ์ ์ ์๊ณ ๋ฆฌ์คํธ๋ฅผ ์ ํํด์ ์ฌ์ฉํ๊ฑด์ง์ ๋ํ๊ฑธ ๋ง์ํ์๋ ๊ฑธ๊น์? ์ด๋ค ์๋ฏธ์ธ์ง ๋ชฐ๋ผ ์ฌ์ญ๋๋คใ ใ
There was a problem hiding this comment.
๋ค ์ฐจ์ด์ ์ด ์๋ค๋๊ฒ ์ ๋ต์ด์์ด์. ใ
ใ
๋ฆฌํฉํ ๋ง์ ๋ถํ๋๋ฆฐ๋ค๋ ์๋ฏธ์ด๊ธฐ๋ ํ๊ตฌ์~
| List<Integer> inputValueOfWinningNumbers = inputWinningNumbers(); | ||
| int bonusNumber = getBonusNumber(); | ||
|
|
||
| Ranking ranking = userLotto.getRankingFromWinningNumbers(inputValueOfWinningNumbers, bonusNumber); |
There was a problem hiding this comment.
inputValueOfWinningNumbers, bonusNumber ๋ ๋จ์ํ ํ๋ผ๋ฉํฐ๋ก ์ ๋ฌ๋๊ธฐ ์ํ ๋ณ์๋ค์ด๊ตฐ์.
๊ทธ๋ ๋ค๋ฉด ๋ณ๋์ ์ ์ธ ์์ด ์๋์ ๊ฐ์ด ํด๋ ๋์ง ์์๊น ์ถ๋ค์.
Ranking ranking = userLotto.getRankingFromWinningNumbers(inputWinningNumbers(), getBonusNumber());There was a problem hiding this comment.
๊ฐ์ฒดํ์
๋ฐํ์ ๊ฒฝ์ฐ๋ ๋ช
์์ ์ผ๋ก ์ ์ด์ฃผ๋ ๊ฒ ์์ ์ฑ ๋ฑ์์ ์ข๋ค๊ณ ์๊ณ ์์์ต๋๋ค.
์ฌ์ค...์ ๊ฒฝ์ฐ์ฒ๋ผ ๋์ผํ ์๋ฏธ๊ฐ ๋ด๊ธด ๋ฉ์๋๋ช
ํ๊ณ ์ฐธ์กฐ๋ณ์๋ช
๋ ๋ฒ ๊ณ ๋ คํ๋๊ฒ ์ ๋ง ์๋ฏธ ์๊ธฐ๋ ํ์์ต๋๋ค.
ํน์ ๋ฌธ์ ๋๊ฑฐ๋ ์ ์ข์ ์ด์ ๊ฐ ์๋ค๋ฉด ๊ตฌ์ฒด์ ์ผ๋ก ์๊ณ ์ถ์ด์์.
์๋ ค์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค.
| } | ||
|
|
||
| public int numberOfWinnings(List<Integer> winningNumbers){ | ||
| public int countNumberOfWinnings(List<Integer> winningNumbers){ |
There was a problem hiding this comment.
stream ์ฌ์ฉํด์ ๊ฐ์ ํ ์ ์์ ๊ฑฐ ๊ฐ๋ค์
| if (sixNumbers.contains(bonusNumber)){ | ||
| return true; | ||
| } | ||
| return false; |
There was a problem hiding this comment.
์ด๋ ๊ฒ ๋ฐ๊ฟ ์ ์์ง ์์๊น์
| if (sixNumbers.contains(bonusNumber)){ | |
| return true; | |
| } | |
| return false; | |
| return sixNumbers.contains(bonusNumber)); |
| @@ -1,4 +1,4 @@ | |||
| package domains; | |||
| package domains.users; | |||
There was a problem hiding this comment.
ํจํค์ง๋ช ์ ๋ณต์ํ์ ์ ์ฐ์ง ์์ต๋๋ค.
There was a problem hiding this comment.
ํ์ฌ๋ ํ๋ช
์ ์
๋ ฅ๋ง ๋ฐ์์ ๋ณต์ํ ์ฐ์ง ์๋๊ฒ ๋ง๊ณ , ์คํ๋ง์ ๊ฒฝ์ฐ์๋ ์ฌ๋ฌ ์ฌ์ฉ์ ์ ๋ณด๋ฅผ ๋ค๋ฃจ๋ ๋ณต์ํ์ ์ฐ๋๊ฒ ๋ง๋ค๊ณ ์๊ฐํ๋ฉด ๋ ๊น์?
์คํ๋ง ๊ฐ์์์ ํจํค์ง๋ช
์ ๋ณต์ํ์ผ๋ก ์ฐ๋ผ๊ณ ํ์
จ์ด์,.. ์ข ๋ ๊ตฌ์ฒด์ ์ผ๋ก ์๊ณ ์ ๋ฆฌํ๊ณ ์ ์ง๋ฌธ ํฉ๋๋ค.
๊ฐ์ฌํฉ๋๋ค.
There was a problem hiding this comment.
์ผ๋จ domains ๊น์ง๋ ์ ์ดํด๊ฐ ๋์๊ตฌ์,
users ๊ฐ ๋ณต์ํ์ด ๋ ์ด์ ๋ฅผ ์๊ณ ์ถ์์ด์. ๋ณต์ํ์ด ๋๋ฉด ์๋๋ค๊ณ ์๊ฐํ๊ตฌ์.
user ๋ผ๋ ์ผ๋ฐ์ ์ธ ๊ฐ๋
, ํน์ ํ๋ก๊ทธ๋จ์ ์๊ตฌ์ฌํญ์ ๊ตฌํํ ์ฝ๋๋ค์ ์งํฉ์ด๋ผ users ๋ผ๋ ๊ฑด ์ข ์ด์ํ๋ค๊ณ ๋ดค๊ฑฐ๋ ์. ์ฐ๋ฆฌ๊ฐ ์ถ์ํํด์ผ ํ ๊ฐ๋
์์ฒด๋ user ๋ผ๊ณ ํํ๋๋๊ฒ ๋ง๋ค๊ณ ๋ด์์.
์คํ๋ง ๊ฐ์์์ ํจํค์ง๋ช
์ ๋ํด ์ด๋ป๊ฒ ๋ค๋ฃจ๊ณ ์๋์ง๋ ์ ๋ชจ๋ฅด๊ฒ ๋ค์.
There was a problem hiding this comment.
๋ค, ๋ง์ํด ์ฃผ์ ๋ถ๋ถ์ ์ดํดํ ์ ์์๊ฑฐ ๊ฐ์์.
์ ๋ ๋จ์ ์ง์์ด์๋๋ฐ, ์ค๋ช
๊ฐ์ฌํฉ๋๋ค. ํ๋ก์ ํธ๋ ๋จ์ํ์ผ๋ก ๋ณ๊ฒฝํ์ต๋๋ค. :)
| int winningCount = lotto.countNumberOfWinnings(winning); | ||
| if (winningCount >= MINIMUM_NUMBER_OF_WINNING) { | ||
| boolean checkedBonus = lotto.getBonus(winningNumbers.getBonus()); | ||
| ranking.record(checkedBonus, winningCount); | ||
| } |
There was a problem hiding this comment.
Lotto ๊ฐ ๊ฐ๊ณ ์๋ ๋น์ฒจ ๋ฒํธ ๊ฐฏ์๋ฅผ ๋ฌผ์ด๋ณด๊ณ , ๋ณด๋์ค๊น์ง ๊บผ๋ด์์ ์ฒดํฌํ ๋ค์ Ranking ๊ฐ์ฒด์ set์ ํด์ฃผ๊ณ ์๊ตฐ์.
๊ทธ๋ฌ์ง ๋ง๊ณ Lotto ๊ฐ์ฒด๊ฐ ์ง์ Ranking ๊ฒฐ๊ณผ๊ฐ์ ์ฃผ๋ ๋ฐฉ์์ผ๋ก ๊ฐ์ ํด์ผ ํ์ง ์์๊น์?
There was a problem hiding this comment.
์ค๊ฐ์ WinningNumber๋ก ๋ถ๋ฆฌํ๊ณ , Ranking ๋ฐํ ๋ฑ ๊ฐ์ ํ๋ฉด์, ์์ผ๊ฐ ์ข์์ง๊ณ , ์ข ๋ ๋ถ๋ช
ํ๊ฒ ์ ๋ฆฌํ์ง ๋ชป ํ๊ฑฐ ๊ฐ์์.
๊ฐ์ฌํฉ๋๋ค.
| } | ||
| } | ||
|
|
||
| private List<List<Integer>> getPurchasedLottos() { |
There was a problem hiding this comment.
๋น์ฒจ๋ฒํธ ๋ฆฌ์คํธ๋ฅผ ๋ณด๊ดํ ๋งํ ๊ฐ์ฒด๋ฅผ ์ค๊ณํด์ ๊ทธ ๊ฐ์ฒด์ ๋ฆฌ์คํธ๋ก ์ ๋ฌํด์ฃผ๋ฉด ๋ ์ข์ํ ๋ฐ์?
| } | ||
|
|
||
| public List<List<Integer>> getTickets(PurchasedLotto purchasedLotto) { | ||
| ArrayList<ArrayList<Integer>> tickets = lottoMachine.getTicket(purchasedLotto.getNumberOfTicket()); |
There was a problem hiding this comment.
java.util.ArrayList ์๋ง ์กด์ฌํ๋ ๋ฉ์๋๋ ๋ก์ง์ ์ ํ๋ฆฌ์ผ์ด์
์ด ๊ฐ๊ฒฐํฉ๋์ด์ผ ํ ํน๋ณํ ์ด์ ๊ฐ ์์๊น์?
๊ทธ๋ ์ง ์๋ค๋ฉด ํญ์ List<T> ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
์ด์ ๋ ์ฌ๋ฌ๊ฐ์ง๊ฐ ์๋๋ฐ์... https://stackoverflow.com/questions/9852831/polymorphism-why-use-list-list-new-arraylist-instead-of-arraylist-list-n ๋ฅผ ์ฐธ๊ณ ํด๋ณด์ธ์.
There was a problem hiding this comment.
์๊ตฌ์ฌํญ ์ค์ "ArrayList๋ฅผ ์ฌ์ฉํด์ ๊ตฌํํ๋ค." ๊ฐ ์์๋๋ฐ ๋จ์ํ๊ฒ ๋ฐํํ์
๊น์ง ์จ์ผ ํ๋ค๊ณ ์๊ฐํ๊ณ ์์
ํ๋๊ฑฐ ๊ฐ์ต๋๋ค.
์ด๋ฒ์ ํ์ด ํ๋ฉด์, ์์์ ์ธ๊ธ๋ ๋ถ๋ถ๋ค๋ ๊ทธ๋ ๊ณ
์ฒด๋ ฅ๊ณผ ์ง์ค๋ ฅ์ด ๋ง์ด ๋จ์ด์ ธ์ ๋๊น์ง ์ ๋ฆฌ ์ ํ ๋ถ๋ถ๋ค์ด ์์๋๋ฐ,
์ข๋ ์ง์คํด์ ๊ฐ์ ํ๋๋ก ์ด๋์ด์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค.
๋ ๋ณด๋ค ์ข์ ์ง์ ์๊ฒ ๋ ๊ฑฐ ๊ฐ์์. ๊ฐ์ฌํฉ๋๋ค.
- Lotto ๊ฐ์ฒด ๋ด๋ถ์์ ์ง์ Ranking ์ฒดํฌ - Tickets : ์ฌ์ฉ์๊ฐ ๊ตฌ๋งคํ ๋ก๋ ๋ชฉ๋ก๋ค (WinningNumber : ๋น์ฒจ๋ฒํธ ๋ฆฌ์คํธ) - ArrayList -> List ๋ณ๊ฒฝ - ํจํค์ง๋ช ๋จ์ํ์ผ๋ก ๋ณ๊ฒฝ - for๋ฌธ stream์ผ๋ก ๊ฐ์ - boolean ๋ฐํํ๋ ํจ์์ด์ฉ์ ๋ถํ์ํ ์กฐ๊ฑด๋ฌธ ์ ๊ฑฐ
refactor: ๋ฆฌ๋ทฐ ๋ฐ์
java-lotto
๋ง์คํฐ์ฆ ๋ฉค๋ฒ์ค 2022 ๋ก๋ ๊ฒ์ ํ๋ก์ ํธ
๊ธฐ๋ฅ์๊ตฌ์ฌํญ
ํ๋ก๊ทธ๋๋ฐ ์๊ตฌ์ฌํญ
์ถ๋ ฅ ๊ฒฐ๊ณผ